<?php

namespace App\V3\V3_2_6\Controllers;

use App\V3\V3_2_6\Models\AdminAddendumModel;
use Illuminate\Http\Request;

class ShareSettingController extends BaseController
{
    /**
     * 共享设置公共方法
     * @param Request $request
     * 2022/8/22 18:08
     * Author: Sun Wu
     * @return \Illuminate\Http\JsonResponse
     */
    public function shareSetting(Request $request)
    {
        switch($request->input('type'))
        {
            case 15:
                $msg = "共享仓库操作";
                $flag = 'is_share_storage_operate';//是否共享仓库操作;0:否;1:是;
                break;
            case 14:
                $msg  = "序列号";
                $flag = 'is_use_serial';//是否使用序列号;0:否;1:是;
                break;
            case 13:
                $msg  = "是否将客户作为供应商使用";
                $flag = 'is_set_as_supplier';//是否将客户作为供应商使用;0:否;1:是;
                break;
            case 12:
                $msg  = "共享仓库";
                $flag = 'is_share_store';//共享仓库：1是 0否
                break;
            case 11:
                $msg  = "共享操作记录";
                $flag = 'is_share_operating_record';//共享操作记录：1是 0否
                break;
            case 10:
                $msg  = "共享销售";
                $flag = 'is_share_sell';//共享销售：1是 0否
                break;
            case 9:
                $msg  = "共享采购";
                $flag = 'is_share_purchase';//共享采购：1是 0否
                break;
            case 8:
                $msg  = "共享退货";
                $flag = 'is_share_sales_return';//共享退货：1是 0否
                break;
            case 7:
                $msg  = "是否共享客户";
                $flag = 'is_share_customer';//是否共享客户;0:否;1:是;
                break;
            case 6:
                $msg  = "是否共享供应商";
                $flag = 'is_share_supplier';//是否共享供应商;0:否;1:是;
                break;

            case 5:
                $msg  = "共享报损";
                $flag='is_share_breakage';//共享报损：1是 0否
                break;
            case 4:
                $msg  = "共享报溢";
                $flag='is_share_overflow';//共享报溢：1是 0否
                break;
            case 3:
                $msg  = "共享快递价格计算";
                $flag='is_share_express_price_calculation';//共享快递价格计算：1是 0否
                break;
            case 2:
                $msg  = "共享空白单据";
                $flag='is_share_billhead';//共享空白单据：1是 0否
                break;
            case 1:
                $msg  = "货架库位使用开关";
                $flag ='is_use_shelf';//货架库位使用开关1 使用 0关闭
                break;
            //开启快递信息共享-销售单已有快递单号列表是否共享
            case 0:
                $msg  = "开启快递信息共享";
                $flag = 'is_share_express';//货架库位使用开关1 使用 0关闭
                break;
        }

        $result = self::openSharingSettings($flag,$msg);
        $this->log('共享设置公共方法', $result);
        return $result;
    }

    /**
     * 开启共享设置
     * 2022/8/22 15:47
     * Author: Sun Wu
     * @return \Illuminate\Http\JsonResponse
     */
    protected function openSharingSettings($flag,$msg)
    {
      $adminInfo = AdminAddendumModel::where('main_id', $this->getMainUserId())->first();

        if($adminInfo->$flag) {
            $tag = 0;
        }else {
            $tag = 1;
        }
        AdminAddendumModel::where('main_id', $this->getMainUserId())->update([$flag=>$tag]);
        $this->log($msg, $tag);

        return $this->success($tag);
    }

    /**
     * 共享菜单列表
     */
    public function list(Request $request){
        $fileds = ['is_use_serial','is_set_as_supplier','is_share_store','is_share_operating_record','is_share_sell',
                   'is_share_purchase','is_share_sales_return','is_share_customer','is_share_supplier',
                   'is_share_breakage','is_share_overflow','is_share_express_price_calculation','is_share_express',
                   'is_share_billhead','is_use_shelf','is_share_storage_operate'];
        $info = AdminAddendumModel::select($fileds)
        ->where('main_id', $this->getMainUserId())->first();
        $this->log('共享菜单列表', $info);
        return $this->success($info);
    }
}
